<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'usermanager.jsp' starting page</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/1.3.4/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/wu.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/icon.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
	$(function(){
		$("#add").submit(function(){
			var names=$("input[name='names']").val();
			var pwds=$("input[name='pwds']").val();
			var realnames=$("input[name='realnames']").val();
			var deptnames=$("input[name='deptnames']").val();
			var sexs=$("input[name='sexs']").val();
			var roles=$("input[name='roles']").val();
			var file=$("input[name='file']").val();
			var states=$("input[name='states']").val();
			if(names==""||names==null){
				alert('用户名不能为空');
				return false;
			}else if(names.length>10){
				alert('不能超出最大范围');
				return false;
				}
			if(pwds==""||pwds==null || pwds.length<6){
				alert('密码不能为空,不能小于6位');
				return false;
			}
  			if(realnames==""||realnames==null){
				alert('真实姓名不能为空');
				return false;
			}else if(realnames.length>10){
				alert('不能超出最大范围');
				return false;
				}
			if(deptnames==""||deptnames==null){
				alert('请选择部门');
				return false;
			}
			if(sexs==""||sexs==null){
				alert('请选择性别');
				return false;
			}
			if(roles==""||roles==null){
				alert('请选择角色');
				return false;
			}
			if(states==""||states==null){
				alert('请选择状态');
				return false;
			}
				return true;	
	});
	});
</script>
<script type="text/javascript">
$(function(){
	$(function(){
		$("#add").submit(function(){
			var names=$("input[name='names']").val();
			var pwds=$("input[name='pwds']").val();
			var realnames=$("input[name='realnames']").val();
			var deptnames=$("input[name='deptnames']").val();
			var sexs=$("input[name='sexs']").val();
			var roles=$("input[name='roles']").val();
			var file=$("input[name='file']").val();
			var states=$("input[name='states']").val();
			if(names==""||names==null){
				alert('用户名不能为空');
				return false;
			}
			if(pwds==""||pwds==null || pwds.length<6){
				alert('密码不能为空,不能小于6位');
				return false;
			}
  			if(realnames==""||realnames==null){
				alert('真实姓名不能为空');
				return false;
			}
			if(deptnames==""||deptnames==null){
				alert('请选择部门');
				return false;
			}
			if(sexs==""||sexs==null){
				alert('请选择性别');
				return false;
			}
			if(roles==""||roles==null){
				alert('请选择角色');
				return false;
			}
			if(states==""||states==null){
				alert('请选择状态');
				return false;
			}
				return true;	
	});
	});

});
$(function(){
	var msg=$('#msg').val();
	if(msg!=""){
		$.messager.show({
			title:'info',
			msg:msg
		});
	}
	$('#msg').val("");
});

$(function(){
	$('#search').click(function(){
			var username=$('#username').val();
			var realname=$('#realname').val();
			$("#users").datagrid('load',{
				username:username,
				realname:realname
			});
		});

	$("#users").datagrid({   
		    url:'${pageContext.request.contextPath}/user?op=page',   
		    columns:[[   
		        {field:'id',title:'编号',checkbox:true},   
		        {field:'username',title:'用户名',width:100},   
		        {field:'realname',title:'真实姓名',width:100} ,
		        {field:'role',title:'角色',width:100 ,
		        	formatter:function(value,row,index){
		        		return value.rolename;
		        	}
		        } ,
		        {field:'department',title:'部门',width:100,
		        	formatter:function(value,row,index){
		        		return value.deptname;
		        	}
		        }
		    ]],
		    fitColumns : true,
			autoRowHeight : false,
			striped : true,
			loadMsg : '请等待...',
			pagination : true,
			nowrap : true,
			rownumbers : true,
			fit : true,
			 	toolbar : [{
			 	text:'修改',
				iconCls : 'icon-edit',
				handler : function() {
					var obj = $("#users").datagrid("getSelected");
					$("#uid").val(obj.id);
					$("#door").window({   
					    width:600,   
					    height:400,   
					    modal:true ,
					    title:'修改用户信息',
					    iconCls:'icon-edit'
					}); 
					$('#deptname').combotree({   
					    url: '${pageContext.request.contextPath}/dept?op=dtree',   
				        cascadeCheck:false,
					});
					$("#role").combobox({
							url:'${pageContext.request.contextPath}/role?op=showrole',
							valueField:'id',
							textField:'rolename',
							panelHeight:'auto'
					});
					
					$("#sex").combobox({
							url:'${pageContext.request.contextPath}/user?op=sex',
							valueField:'id',
							textField:'content',
							panelHeight:'auto'
					});
					$("#state").combobox({
							url:'${pageContext.request.contextPath}/user?op=state',
							valueField:'id',
							textField:'carkind',
							panelHeight:'auto'
					});
					$("#update").form('load',{
						name:obj.username,
						pwd:obj.password,
						realname:obj.realname,
						deptname:obj.department.id,
						sex:obj.gender,
						role:obj.role.id,
						upload:obj.image,
						state:obj.state
					});
					}
				}, '-', {
				text:'添加',
				iconCls : 'icon-add',
				handler : function() {
					$("#adduser").window({   
					    width:600,   
					    height:400,   
					    modal:true ,
					    title:'添加用户',
					    iconCls:'icon-add'
					});
					$('#deptnames').combotree({   
					    url: '${pageContext.request.contextPath}/dept?op=dtree',   
				        cascadeCheck:false,
					});
					$("#roles").combobox({
							url:'${pageContext.request.contextPath}/role?op=showrole',
							valueField:'id',
							textField:'rolename',
							panelHeight:'auto'
					});
					
					$("#sexs").combobox({
							url:'${pageContext.request.contextPath}/user?op=sex',
							valueField:'id',
							textField:'content',
							panelHeight:'auto'
					});
					$("#states").combobox({
							url:'${pageContext.request.contextPath}/user?op=state',
							valueField:'id',
							textField:'carkind',
							panelHeight:'auto'
					}); 
				}
				}, '-', {
					text:'删除',
					iconCls : 'icon-remove',
					handler : function() {
					 	var obj = $("#users").datagrid("getSelected");
						var str=confirm("确认删除客户信息?");
						if(str==true){
							location.href='${pageContext.request.contextPath}/user?op=delete&id='+obj.id;
					}
				}
			}]
			
			
		});
		});

</script>
  </head>
  
  <body class="easyui-layout">
  <div><input type="hidden" id="msg" value="${mess}"></div>  
    <div data-options="region:'west',title:'查询条件'" style="width:180px;text-align: center" >
    		<p>&nbsp;&nbsp;&nbsp;&nbsp; 
				用户名:<input type="text" id="username" style="width:120px">
			</p>
			<p>
				真实姓名:<input type="text" id="realname" style="width:120px">
			</p>
			<a href="javascript:void()" id="search" class="easyui-linkbutton">查询</a> 
    
    </div>  
    <div data-options="region:'center'">
    	<table id="users"></table>
    	<!-- 修改 -->
    		<div id="door" style="text-align:center;line-height: 30px">
				<form action="user.html?op=updateuser" id="update" method="post" enctype="multipart/form-data">
					<input name="uid" id="uid" type="hidden">
					 <div>
			            <label for="name">登录名称:</label> 
			            <input class="easyui-validatebox" type="text" name="name" ></input>
			        </div>
			        <div>
			            <label for="pwd">密码:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" name="pwd"></input>
			        </div>
					<div>
			            <label for="realname">真实姓名:</label>
			            <input class="easyui-validatebox" type="text" name="realname" ></input>
			        </div>
			        <div>
			            <label for="deptname">部门:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			        	<input class="change" id="deptname" name="deptname" value="" size="30">
			        </div>
			         <div>
			            <label for="sex">性别:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" id="sex" name="sex"></input>
			        </div>
			        <div>
			            <label for="role">角色:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" id="role" name="role"></input>
			        </div>
			        <div>
			            <label for="file">地址:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="file" name="file"></input>
			        </div>
			        <div>
			            <label for="state">状态:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" id="state" name="state" ></input>
			        </div>
			        <div>
			        	<input type="submit" value="提交" />
			        </div>
				</form>
			</div>
			<!-- 添加 -->
			<div id="adduser" style="text-align: center;line-height: 30px">
				<form action="user.html?op=saveuser" id="add" method="post" enctype="multipart/form-data">
					 <div>
			            <label for="names">登录名称:</label> 
			            <input class="easyui-validatebox" type="text" name="names" ></input>
			        </div>
			        <div>
			            <label for="pwds">密码:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" name="pwds" ></input>
			        </div>
					<div>
			            <label for="realnames">真实姓名:</label>
			            <input class="easyui-validatebox" type="text" name="realnames" ></input>
			        </div>
			        <div>
			            <label for="deptnames">部门:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			        	<input class="change" id="deptnames" name="deptnames" value="" size="30">
			        </div>
			         <div>
			            <label for="sexs">性别:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" id="sexs" name="sexs" value="1"></input>
			        </div>
			        <div>
			            <label for="roles">角色:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="text" id="roles" name="roles"></input>
			        </div>
			        <div>
			            <label for="file">地址:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			            <input class="easyui-validatebox" type="file" name="file" ></input>
			        </div>
			        <div>
			            <label for="states">状态:</label>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
			          <input class="easyui-validatebox" type="text" id="states" name="states" value="0"  ></input>
			        </div>
			        <div>
			        	<input type="submit" value="提交" />
			        </div>
				</form>
			</div>
    </div>
    <div id="dd"></div>
</body>  

</html>
